package com.smartfarm.domain.equipment;

import com.smartfarm.domain.environment.EnvironmentData;
import com.smartfarm.domain.state.EquipmentState;
import com.smartfarm.domain.strategy.PathPlanningStrategy;
import lombok.Getter;
import lombok.Setter;

/**
 * 农业设备抽象基类
 */
@Getter
@Setter
public abstract class BaseAgriculturalEquipment implements AgriculturalEquipment {
    private String id;
    private String name;
    private EquipmentState state;
    private EnvironmentData environmentData;
    private PathPlanningStrategy pathStrategy;
    
    public BaseAgriculturalEquipment(String id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public void updateEnvironmentData(EnvironmentData data) {
        System.out.println(name + "收到环境更新：" + data);
        System.out.println(name + "正在使用" + pathStrategy.getClass().getSimpleName().replace("PathStrategy", "路径规划策略"));
        this.environmentData = data;
        // 根据环境数据调整作业策略
        if (pathStrategy != null) {
            pathStrategy.planPath(this, data);
        }
    }

    @Override
    public void setState(EquipmentState state) {
        this.state = state;
        System.out.println(name + "当前状态：" + state.getClass().getSimpleName().replace("State", "状态"));
    }

    @Override
    public void setPathStrategy(PathPlanningStrategy strategy) {
        this.pathStrategy = strategy;
        changeStrategy(strategy);
    }

    @Override
    public void stop() {
        System.out.println(name + "已停止作业。");
    }
} 